package main.ui;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;

import main.Game.SendInfor;

public class Menu implements FontAPI {
	public static Scanner in = new Scanner(System.in);
	public static SendInfor si = null;

	public Menu() {
		// showhole
	}

	public String playerName() { //启动游戏
		System.out.println("input your name: ");
		String temp;
		in = new Scanner(System.in);
		temp = in.next();
		return temp;
	}

	public int chooseItem() {	//选择你想要的
		System.out.print("input what you want: ");
		int temp = in.nextInt();
		return temp;
	}

	public void buildHost(int PORT, int userNum) {
		System.out.println("Building Host....");
		System.out.println("Player num is: " + userNum);
		System.out.println("Running in PORT: " + PORT);
		this.waitJoin();
	}

	public void waitJoin() {
		System.out.println("Waiting someone join...");
	}

	public void whoConnected(String name) {
		System.out.println(name + " is connected.");
	}

	/**
	 * 人数是否满，是否可以开始游戏
	 * @return 是否可以开始游戏
	 */
	public boolean enableStart() { 
		System.out.println("Ok to start: ");
		System.out.println("Input [start] to Start: ");
		String temp;
		temp = in.next();
		if(temp.equals("start")) {
			return true;
		}
		else return false;
	}

	public boolean joinHost(String name) {
		System.out.println(name + " joined your game.");
		return false;
	}

	/** 
	 * 输入玩家人数
	 * @return 玩家人数
	 */
	public int playNum() { 
		System.out.print("Please input the player num: ");
		int temp;
		temp = in.nextInt();
		return temp;
	}

	/**
	 * 输入加入的ip
	 * @return 输入的ip
	 */
	public String joinIP() {
		cout ("Input the ip you wanna join: ");
		String temp = in.next();
		System.out.println();
		return temp;
	}

	/**
	 * 帮助目录，显示帮助目录（网页)
	 */
	public void helpMenu() {
		// open with html
		// 启用系统默认浏览器来打开网址。
		try {
			URI uri = new URI("http://blog.csdn.net/svitter");
			Desktop.getDesktop().browse(uri);
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 显示错误
	 * @param 错误信息
	 */
	public void error(String str) {
		System.out.println("Error occured at" + str);
	}
	
	/**
	 * 输出字符
	 * @param 想要输出的字符 
	 */
	public static void cout(String str) {
		System.out.println(str);
	}
	
	/**
	 * 调试
	 * @param 想要调试的信息
	 */
	public static void debug(String str) {
		System.out.println("DEBUG: " + str);
	}
	
	/**
	 * 开始游戏
	 * @return 所选择的标号
	 */
	public int start() {
		cout("Welcome to DaVinci Code ~!");
		cout("----show menu----\n" + "1. buildHost;\n"
				+ "2. joinHost;\n" + "3. help;\n" + "4. exit;\n");
		return chooseItem();
	}
	
	/**
	 * 退出游戏
	 */
	public void exit() {
		cout("exiting...");
	}

	@Override
	public int playerNum() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void out(String str) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void debug(String str, boolean isTest) {
		// TODO Auto-generated method stub
		
	}
}
